<template>
	<view class="custom-tabbar">
		<view @click="tabbar(item.path)" :style="itemStyle" class="tab-item" v-for="item in tab">
			<image :style="iconStyle" class="tab-icon" :src="path==item.path?item.selectIcon:item.icon"></image>
			<view
				:style="'color:'+(path==item.path?config.textActiveColor:config.textColor)+';font-size:'+(path==item.path?config.textActiveSize:config.textSize)+';font-weight:'+(path==item.path?config.textActiveWeight:config.textWeight)"
				class="tab-text">{{item.text}}</view>
		</view>
		<view class="scan">
			<view class="scan-in" @click="scanCode">
				<!-- <image
					src="https://job-1306862033.cos.ap-chengdu.myqcloud.com/miniprogram-static/alliance/scanning.png">
				</image> -->
				<image
					src="https://jinchang-job-1306862033.cos.ap-chengdu.myqcloud.com/miniprogram-static/shop/scan.png">
				</image>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		scanJump,
		writeOffConsumptionOrderVoucher,
		writeOffIntegralOrder
	} from '@/api/user.js'
	import {
		businessVerification
	} from '@/api/mine.js'
	import {
		getStorage
	} from '@/util/auth';
	export default {
		data() {
			return {
				path: '',
				tab: [{
						text: '首页',
						path: '/pages/index/index',
						icon: require('@/static/tabbar/home.png'),
						selectIcon: require('@/static/tabbar/home_select.png')
					},
					{
						text: '活动',
						path: '/page_other/activity/activityCategory',
						//path: '/page_other/activities/activities',
						icon: require('@/static/tabbar/activity.png'),
						selectIcon: require('@/static/tabbar/activity_select.png')
					},
					{
						text: '扫一扫',
						path: '',
						icon: '',
						selectIcon: ''
					},
					{
						text: '积分',
						path: '/page_other/integral/index',
						icon: require('@/static/tabbar/integral.png'),
						selectIcon: require('@/static/tabbar/integral_select.png')
					},
					{
						text: '我的',
						path: '/page_other/mine/mine',
						icon: require('@/static/tabbar/mine.png'),
						selectIcon: require('@/static/tabbar/mine_select.png')
					},
				],
				config: {
					iconSize: '55rpx',
					// textColor: '#D8D8D8',
					textColor: '#FF2F34',
					textActiveColor: '#FF2F34',
					textSize: '28rpx',
					textActiveSize: '32rpx',
					textActiveWeight: 'bold',
					textWeight: 'normal',

				},
				code: ''
			}
		},
		mounted() {
			let pages = getCurrentPages();
			this.path = '/' + pages[pages.length - 1].__route__;
			uni.$on('pathChange', (e) => {
				this.path = e;
			})
		},
		methods: {
			tabbar(path) {
				if (path) {
					uni.redirectTo({
						url: path
					})
				}
			},

			scanCode() {
				if (getStorage('token')) {
					uni.scanCode({
						onlyFromCamera: false,
						success: (res) => {

							if (res.result) {
								if (res.result.includes('classification=5#')) {
									this.result = res.result
									uni.navigateTo({
										url: '/page_other/verify/index?consumption='+res.result
									})
								}else if (res.result.includes('classification=6#')) {
									writeOffConsumptionOrderVoucher({
										verificationCode: res.result,
									}).then((res) => {
										this.showToast('兑换成功', () => {}, 2000)
										uni.navigateTo({
											url: '/page_other/mine/mine'
										})
									})
								} else if (res.result.includes('goods=2#')) {
									writeOffIntegralOrder({
										code:res.result
									}).then(res => {
										
										this.showToast('兑换成功', () => {}, 2000)
										uni.navigateTo({
											url: '/page_other/mine/mine'
										})
									})
								} else if(res.result.includes('type=2&')) {
									console.log(res.result)
									let list = res.result.split('&');
									this.code = list[1]
									if (list[[0]] === 'type=2') {
										uni.navigateTo({
											url: '/page_other/accounts/accounts?code=' + this.code
										})
									}
								}else {
									this.showToast('请扫正确的收款码！')
									
								}
							
							}

						}
					});
				} else {
					uni.showModal({
						title: '提示',
						content: '需要先登录！',
						cancelText: '先逛逛',
						confirmText: '去登录',
						success(res) {
							if (res.confirm) {
								uni.reLaunch({
									url: '/page_other/mine/mine'
								})
							} else {
								uni.navigateBack();
							}
						}
					})
				}
			}
		},
		computed: {
			itemStyle() {
				return ''
			},
			iconStyle() {
				return `width:${this.config.iconSize};height:${this.config.iconSize}`
			},
		}
	}
</script>

<style lang="scss" scoped>
	.custom-tabbar {

		z-index: 999;
		width: 100vw;
		height: 160rpx;
		padding-bottom: 20rpx;
		background: #fff;
		display: flex;
		align-items: center;
		flex-wrap: nowrap;
		border-radius: 7px 7px 0 0;

		.tab-item {
			flex-grow: 1;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;

			.tab-icon {
				margin-bottom: 10rpx;
			}
		}

		.tab-item:nth-child(2) {
			margin-right: 30rpx;
		}

		.tab-item:nth-child(4) {
			margin-left: 30rpx;
		}

		.scan {
			position: absolute;
			z-index: 9999;
			background: #F7F6F9;
			width: 180rpx;
			height: 180rpx;
			border-radius: 50%;
			transform: translate(-50%, -50%);
			left: 50%;
			top: 0;
			padding: 20rpx;

			.scan-in {
				z-index: 9999;
				width: 100%;
				height: 100%;
				border-radius: 50%;
				background-image: linear-gradient(to right, #FF3432, #FF671A);
				display: flex;
				align-items: center;
				justify-content: center;

				image {
					width: 60rpx;
					height: 60rpx;
				}
			}
		}
	}
</style>